<!DOCTYPE html>
<!-- Currently we have tests for a service worker which is registered just
 before issuing network requests for the test in
 wpt/service-workers/service-worker/service-worker-csp-default.https.html,
 and this is the similar test for installed service workers since the path to
 rovide installed scripts is different when the scripts have already been
 installed and script streaming is enabled. See https://crrev.com/c/613001. -->
<title>
Service Worker: CSP default directive for ServiceWorker installed script
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<script>

function create_csp_test(worker_url) {
  return test => {
    let scope = new URL('scope' + window.location.pathname,
                        new URL(worker_url, window.location)).toString();
    return service_worker_unregister_and_register(test, worker_url, scope)
      .then(reg => {
          add_completion_callback(() => {
              reg.unregister();
            });
          var sw = reg.installing;
          return new Promise(resolve => {
              return wait_for_state(test, sw, 'activated')
                .then(() => { resolve(sw); });
            });
        })
      .then(sw => internals.terminateServiceWorker(sw))
      .then(() => navigator.serviceWorker.getRegistration(scope))
      .then(r => {
          fetch_tests_from_worker(r.active);
        });
    }
}

promise_test(
  create_csp_test('resources/fetch-with-csp-worker.php?directive=default'),
  'CSP test for default-src in installed ServiceWorkerGlobalScope');

</script>
